import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/16 20:55
 * @description 枚举
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int perfectMenu(int[] materials, int[][] cookbooks, int[][] attribute, int limit) {
        int n = cookbooks.length;
        int ans = -1;
        int[] ma;
        for (int i = 0; i < n; i++) {
            // 美味度，饱腹度
            int delicious = 0, satiety = 0;
            ma = Arrays.copyOf(materials, materials.length);
            boolean canCook = true;
            for (int j = i; j < n; j++) {
                int[] cook = cookbooks[j];
                // 先检查是否可分配
                for (int k = 0; k < 5; k++) {
                    if (cook[k] > ma[k]) {
                        canCook = false;
                        break;
                    }
                }
                if (!canCook) {
                    // 不可分配，继续下一道料理
                    canCook = true;
                    continue;
                }
                // 可以分配，食材减少
                for (int k = 0; k < 5; k++) {
                    ma[k] -= cook[k];
                }
                delicious += attribute[j][0];
                satiety += attribute[j][1];
            }
            if (satiety >= limit) {
                ans = Math.max(ans, delicious);
            }
        }
        return ans;
    }
}
